﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FacadeSingTowerMall;
using DTOSingTowerMall;

namespace WebFormSingTowerMall
{
    public class TransactionBaseController : System.Web.UI.Page
    {
// Navigator keeps the flow map for the reservation 
        // The key is the "currentpage.aspx" string the value is the "nextpage.aspx"
        private Dictionary<string, string> navigator;
      
        // The current page 'id' would be set in this variable by the deriving page
        protected string currentPage;
        
        // The reservation facade is a Business Interface providing services for accessing BLL functionality 
        protected TransactionsFacade transactionFacade;
       
        // The reservation view object is a strongly typed session state object structure 
        // for storing reservation information that is shared by all pages participating in this flow
        protected TransactionViewObject paymentDetails;

        // To be called for intialisation by the deriving class Page_Load
        protected virtual void Page_Load(object sender, EventArgs e)
        {
            // This could be improved by keeping navigator as a singleton
            // This could be improved by using enumerations instead of string
            // Shown here for clarity of purpose for page controller pattern
            navigator = new Dictionary<string, string>();
            navigator.Add("EventsBookHistory.aspx", "HallBooking/Payment.aspx");
            navigator.Add("Payment.aspx", "~/Default.aspx");
           // navigator.Add("MemberDetails.aspx", "ConfirmBooking.aspx");
            //navigator.Add("MemberDetails.aspx", "Payment.aspx");
           // navigator.Add("Payment.aspx", "ConfirmBooking.aspx");
           // navigator.Add("ConfirmBooking.aspx", "~/Default.aspx");

            transactionFacade = new TransactionsFacade();

            if (Session["PaymentDetails"] == null)
            {
                paymentDetails = new TransactionViewObject();
                Session["PaymentDetails"] = paymentDetails;
            }
            else
                paymentDetails = (TransactionViewObject)Session["PaymentDetails"];
        }

        // Navigator to be used to move to next step (view) in the process
        protected void NextPage()
        {
            Response.Redirect(navigator[currentPage]);
        }

        protected void ConfirmPayement()
        {
            //int hallId = Convert.ToInt32( HallIDTxtBx.Text);
            //string hallName = HallNameTxtBx.Text;
            //string eventTitle = EventTitleTxtBx.Text;
            //string eventDesc = HallDescTxtBx.Text;
            //DateTime startDate = Convert.ToDateTime (StartDateTxBx.Text);
            //DateTime endDate = Convert.ToDateTime (EndDateTxBx.Text);
            //string imgPath = UploadImgTxBx.Text;
            bool transSuccess = transactionFacade.makePyament(paymentDetails.bookingId, paymentDetails.paymentamount);
            if (transSuccess)
            {

                string script = "alert('Payement has been successfull.Now you can see event on SingTower Website');";
                ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", script, true);

            }

           // resFacade.ConfirmBooking(); // This is a dummy call - you would need to pass attributes as reservation details as argument (not the view object).
           // Response.Redirect(navigator[currentPage]);
        }
    }
}